package migrations

import (
	"github.com/goravel/framework/contracts/database/schema"
	"github.com/goravel/framework/facades"
)

type M20250703094612CreateLoginLogTable struct {
}

// Signature The unique signature for the migration.
func (r *M20250703094612CreateLoginLogTable) Signature() string {
	return "20250703094612_create_login_log_table"
}

// Up Run the migrations.
func (r *M20250703094612CreateLoginLogTable) Up() error {
	if !facades.Schema().HasTable("login_log") {
		return facades.Schema().Create("login_log", func(table schema.Blueprint) {
			table.ID()
			table.Integer("user_id").Comment("用户ID")
			table.String("user_name").Comment("用户名")
			table.String("login_ip").Comment("登录IP")
			table.String("user_agent").Comment("浏览器UA")
			table.TimestampsTz()
			table.Index("user_name")
		})
	}

	return nil
}

// Down Reverse the migrations.
func (r *M20250703094612CreateLoginLogTable) Down() error {
	return facades.Schema().DropIfExists("login_log")
}
